<?php
/**
* $Id: imageresizer.php 5994 2010-03-03 05:05:10Z huong.pham $
* Resize image class base on Fleximage library
*/
require_once('fleximage.php');
//$CI =& get_instance();
define('CACHE_DIR', 'uploadedfiles/temp/');
class ImageResizer{
    public static function isImage($imagePath){
        return FlexImage::isImage($imagePath);
    }
    
    public static function resize($oldImagePath, $newImagePath, $width, $height)
    {
        $fleximage = new FlexImage($oldImagePath);
        if ($fleximage->errorMessage != null)
            return $fleximage->errorMessage;
        else
            return $fleximage->resize($newImagePath, $width, $height);    
    }
    
    public static function thumb($oldImagePath, $newImagePath, $width, $height, $r = 255, $g = 255, $b = 255)
    {
        $fleximage = new FlexImage($oldImagePath);
        if ($fleximage->errorMessage != null)
            return $fleximage->errorMessage;
        else
            return $fleximage->frame($newImagePath, $width, $height, array($r,$g,$b));
    }
    
    public static function cropCenter($oldImagePath, $newImagePath, $width, $height)
    {
        $fleximage = new FlexImage($oldImagePath);
        if ($fleximage->errorMessage != null)
            return $fleximage->errorMessage;
        else
            return $fleximage->resize($newImagePath, $width, $height, false, '1:1');    
    }
}  
?>
